package cn.buk.tms.report.service;

import cn.buk.tms.dto.SettlementReportDto;
import cn.buk.tms.entity.misc.EntDepartment;
import cn.buk.qms.service.BaseAbstractService;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.stereotype.Service;

@Service
public class ReportExportServiceImpl extends BaseAbstractService implements ReportExportService  {

  @Override
  public double exportSettlementToExcel(int enterpriseId, SettlementReportDto dto, Sheet sheet, int templateId0) {
    final int templateId = templateId0 > 0 ? templateId0: dto.getReportTemplateId();
    double exportedTotal = 0;
    if (templateId == 1) {
      exportedTotal =  ReportExportExcelFormat1.exportSettlementToExcel(dto, sheet);
    } else if (templateId == 2) {
      exportedTotal =  ReportExportExcelFormat2.exportSettlementToExcel(dto, sheet);
    } else if (templateId == 3) {
      exportedTotal = ReportExportExcelFormat3.exportSettlementToExcel(dto, sheet);
    }

    if (exportedTotal != dto.getAmount()) {
      doSendAlert(enterpriseId, "结算单(" + dto.getSettlementNo() + ", 模板" + templateId + ")导出: " + exportedTotal + " != " + dto.getAmount(), null, EntDepartment.DEPT_CASHIER);
    }

    return exportedTotal;
  }


}
